<template>
  <div class="app-container">
    <div class="filter-container">
      <el-button class="filter-item" type="primary" icon="el-icon-plus" @click="addVip">
        添加会员等级
      </el-button>
    </div>
    <el-table
      :data="list"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="id" label="编号" />
      <el-table-column prop="name" label="会员等级名称" />
      <el-table-column label="排序">
        <template slot-scope="item">
          <el-input v-model="item.row.sort" style="width: 92%" autocomplete="off" clearable />
        </template>
      </el-table-column>
      <el-table-column label="操作" width='200'>
        <template slot-scope="item">
          <el-button type="primary" size='mini' icon="el-icon-edit" @click="handleUpdate(item.row)" />
          <el-button type="danger" size='mini' icon="el-icon-delete" @click="handleDelete(item.row.id)" />
        </template>
      </el-table-column>
    </el-table>
    <!------------------------- 基本信息 ------------------------------>
    <el-dialog :title="isAdd?'添加会员等级':'编辑会员等级'" :visible.sync="formVisible" width="40%" @close="handleCancel">
      <el-form :ref="formName" :model="formFieldsData" :rules="rules">
        <el-form-item label="会员等级名称：" :label-width="formLabelWidth" prop="name">
          <el-input v-model="formFieldsData.name" style="width: 92%" autocomplete="off" clearable />
        </el-form-item>
        <el-form-item label="排序：" :label-width="formLabelWidth">
          <el-input v-model="formFieldsData.sort" style="width: 92%" autocomplete="off" clearable />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel">取 消</el-button>
        <el-button type="primary" @click="vipSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import formOperate from '@/layout/mixin/formOperate'
import { parseTime } from '@/utils'

export default {
  name: 'Index',
  mixins: [formOperate],
  data() {
    return {
      list: [
        {id:1,name:'职位类型',sort:1}
      ], // 会员列表
      formName: 'vipuser',
      formLabelWidth: '140px',
      formFieldsData: {
        id:'',
        name: '',
        sort:''
      },// 表单input值
      rules: {
        name: [
          { required: true, message: '请输入属性名称', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 1 到 10 个字符', trigger: 'blur' }
        ]
      },// 验证规则
      url:'', // 添加，编辑ajax提交地址
      isAdd:false // 添加还是编辑
    }
  },
  methods: {
    // 添加会员等级
    addVip() {
      this.isAdd = true
      this.handleCreate()
    },
    sync() {
      this.$http.post('wechat/official/menus/sync').then(res => {
        this.$message.success(res.message)
        this.handleRefresh()
      })
    },
    // 编辑添加会员提交前
    vipSubmit() {
      if (this.isAdd) {
        this.url = ''
      } else {
        this.url = ''
      }
      this.handleSubmit()
    }
  }
}
</script>